package com.blb.service.impl;

import com.blb.entity.Hint;
import com.blb.mapper.HintMapper;
import com.blb.service.IHintService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blb.utils.ShiroUtils;
import com.blb.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaoxiong
 * @since 2020-05-20
 */
@Service
public class HintServiceImpl extends ServiceImpl<HintMapper, Hint> implements IHintService {

    @Resource
    private HintMapper hintMapper;

    @Override
    public List<Map> hintAll(Map map2) {
        //公司ID
        String company = ShiroUtils.getCompany();
        map2.put("company",company);

        List<Map> maps = hintMapper.hintAll(map2);
        for (Map map : maps) {
            Map map1 = hintMapper.oneHint(map);
            map.put("id", map1==null?"":map1.get("id"));
            map.put("hint",map1==null?"":map1.get("hint"));
        }
        return maps;
    }
    
    @Override
    public void updateHint(Map map) {
        //公司ID
        String company = ShiroUtils.getCompany();
        map.put("company",company);

        String id= (String) map.get("id");
        if (id.equals("")||id.equals(null)){
             map.put("id", UUIDUtils.getId());
             hintMapper.addHint(map);
        }else{
            hintMapper.updateHint(map);
        }
    }

    @Override
    public int recordsTotal(Map map) {
        //公司ID
        String company = ShiroUtils.getCompany();
        map.put("company",company);
        return hintMapper.recordsTotal(map);
    }
}
